import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="darkgrid") #这是seaborn默认的风格


# ================= 1 "tips"
#数据来源可在seaborn的GitHub上查找
tips = sns.load_dataset("tips")
print(tips.columns)
print(tips.head())

ax = sns.boxplot(x="day", y="total_bill", data=tips)
plt.show()

#这些参数不一定要加，简单最好，这里只是为了展示参数的含义
ax = sns.boxplot(x="day", y="total_bill", hue="time",data=tips,
                 linewidth=0.5,saturation=1,width=1,fliersize=3)
plt.show()

ax = sns.violinplot(x="day", y="total_bill", data=tips)
plt.show()

#设置按性别分类，调色为“Set2”，分割，以计数的方式，不表示内部。
ax = sns.violinplot(x="day", y="total_bill", hue="sex",data=tips,
palette="Set2", split=True,scale="count", inner=None)
plt.show()

ax = sns.boxplot(x="tip", y="day", data=tips, whis=np.inf)
ax = sns.stripplot(x="tip", y="day", data=tips,jitter=True, color="c")
plt.show()

ax = sns.violinplot(x="tip", y="day", data=tips, inner=None,whis=np.inf)
ax = sns.stripplot(x="tip", y="day", data=tips,jitter=True, color="c")
plt.show()

ax = sns.barplot(x="day", y="total_bill", hue="sex", data=tips)
plt.show()

ax = sns.barplot(x="day", y="total_bill",hue='sex', data=tips,
estimator=np.median,capsize=0.2,errcolor='c')
plt.show()

# ================= 2 "titanic"
titanic = sns.load_dataset("titanic")
ax = sns.countplot(x="class", hue="who", data=titanic)
plt.show()

np.random.seed(666)
x = np.random.randn(1000)
ax = sns.distplot(x)
plt.show()

#修改更多参数，设置方块的数量，方块、密度曲线和边际毛毯都显示，颜色为‘k’，axlabel=‘norm’。
np.random.seed(666)
x = np.random.randn(1000)
ax = sns.distplot(x, bins=100, hist=True, kde=True, rug=True,color='k',axlabel='norm')
plt.show()

# ================= 3 "tips"
tips = sns.load_dataset("tips")
g = sns.jointplot(x="total_bill", y="tip", data=tips,height=5)
plt.show()

g = sns.lmplot(x="total_bill", y="tip", hue="smoker", data=tips)
plt.show()

g = sns.lmplot(x="total_bill", y="tip", col="day", hue="day",data=tips,
 col_wrap=2, height=4)
plt.show()

# ================= 4 "iris"
#用密度估计替换散点图和直方图，调节间隔和比例：
iris = sns.load_dataset("iris")
g = sns.jointplot("sepal_width", "petal_length", data=iris,kind="kde", space=0,ratio=6 ,color="r")
plt.show()

#iris = sns.load_dataset("iris")
g = sns.pairplot(iris)
plt.show()

#使用hue="species"对不同种类区分颜色绘制，并使用不同标记：
g = sns.pairplot(iris, hue="species", markers=["o", "s", "D"])
plt.show()

# =========== random
x = np.random.rand(10, 12)
ax = sns.heatmap(x)
plt.show()

x= np.random.rand(10, 10)
ax = sns.heatmap(x,annot=True,annot_kws={'size':9,'weight':'bold', 'color':'w'},fmt='.2f')
plt.show()
